package site.lanmushan.generate.entity;

import lombok.Data;
import site.lanmushan.generate.conts.Constant;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 * @date 2017/5/16
 */
@Data
public class Table {
    private String appCode;
    //数据库
    private String tableSchema;
    //表名称
    private String tableName;
    //转换后的类名称
    private String entityName;
    //表注释
    private String tableNote;
    //是否为关系表
    private Integer isRelation = 0;
    //包名
    private String packageName;
    //项目名称
    private String projectName;
    private List<Column> columnList = new ArrayList<Column>();
    private List<Column> fullColumnList = new ArrayList<Column>();

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
        String[] classNameArray = tableName.replaceAll(Constant.TABLE_SUBSTITUTION, "").split(Constant.TABLE_INTERVAL);
        entityName = "";
        for (int i = 0; i < classNameArray.length; i++) {
            entityName += classNameArray[i].substring(0, 1).toUpperCase() + classNameArray[i].substring(1).toUpperCase().toLowerCase();
        }
        this.setEntityName(entityName);
        String pk = tableName.substring(0, tableName.indexOf(Constant.TABLE_INTERVAL));
        this.setPackageName(pk.substring(0, 1).toUpperCase() + pk.substring(1, pk.length()));
        if (tableName.indexOf(Constant.RELATIONAL_SUBSTITUTION) >= 0) {
            this.setIsRelation(1);
        }
    }

    public String getEntityName() {
        return entityName;
    }

    public void setEntityName(String entityName) {
        this.entityName = entityName;
    }

    public String getTableNote() {
        return tableNote;
    }

    public void setTableNote(String tableNote) {
        this.tableNote = tableNote;
    }

    public Integer getIsRelation() {
        return isRelation;
    }

    public void setIsRelation(Integer isRelation) {
        this.isRelation = isRelation;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public List<Column> getColumnList() {
        return columnList;
    }

    public void setColumnList(List<Column> columnList) {
        this.columnList = columnList;
    }


    @Override
    public Object clone() {
        Table t = new Table();
        t.setTableName(tableName);
        t.setTableNote(tableNote);
        t.setIsRelation(isRelation);
        t.setPackageName(packageName);
        t.setProjectName(projectName);
        t.setColumnList(columnList);
        return t;
    }

    public String getProjectName() {
        return projectName;
    }

    public void setProjectName(String projectName) {
        this.projectName = projectName;
    }

    @Override
    public String toString() {
        return "Table{" +
                "tableName='" + tableName + '\'' +
                ", className='" + entityName + '\'' +
                ", tableNote='" + tableNote + '\'' +
                ", isRelation=" + isRelation +
                ", packageName='" + packageName + '\'' +
                ", projectName='" + projectName + '\'' +
                ", columnList=" + columnList +
                '}';
    }
}
